<template>
    <div id="app">
        <router-view></router-view>
    </div>
</template>

<script>
export default {
    name: 'App',
    created() {
        this.messageMount()
    },
    mounted() {
        this.sendMessage()
    },
    beforeDestroy() {
        this.messageUnMount()
    },
    methods: {
        messageMount() {
            window.addEventListener('message', this.handleMessage, false)
        },
        messageUnMount() {
            window.removeEventListener('message', this.handleMessage, false)
        },
        handleMessage(res) {
            if (window.location.origin !== res.origin) {
                // this.msg = res.data;
                this.msg=111
                if (res.data && res.data.token) {
                    this.$store.dispatch('setToken', {
                        token: res.data.token || null,
                        tenantId: res.data.tenantId || 1
                    })
                }
            }
        },
        sendMessage() {
            if (window.parent) {
                // 0 初始化完成
                window.parent.postMessage("0", '*')
            }
        }
    }
}
</script>

<style lang="scss">
</style>
